package com.eoe.wiki.activity;

import org.codehaus.jackson.map.ObjectMapper;

import com.eoe.wiki.WikiApplication;
import com.umeng.analytics.MobclickAgent;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

public class BaseActivity extends Activity {

	public final static String ACTION_EXIT = "com.eoe.wiki.ACTION_EXIT";
	
	protected WikiApplication mWikiApplication = null;
	protected BaseActivity mContext= null;
	protected ObjectMapper mObjectMapper = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		MobclickAgent.updateOnlineConfig(this);
		MobclickAgent.onError(this);
		
		mContext = this;
		mWikiApplication = WikiApplication.getApplication();
		mObjectMapper = new ObjectMapper();
		registerReceiver(exitReceiver, new IntentFilter(ACTION_EXIT));
	}
	
	private BroadcastReceiver exitReceiver = new BroadcastReceiver() {
		
		@Override
		public void onReceive(Context context, Intent intent) {
			// TODO Auto-generated method stub
			if(ACTION_EXIT.equals(intent.getAction())){
				mContext.finish();
			}
		}
	};
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		MobclickAgent.onResume(mContext);
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		MobclickAgent.onPause(mContext);
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		unregisterReceiver(exitReceiver);
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}
	
	public WikiApplication getWikiApplication(){
		return this.mWikiApplication;
	}
}
